package cn.tedu._06artice.base.Interceptor;

import cn.tedu._06artice.pojo.dto.UserLoginParam;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerInterceptor;

@Configuration
@Slf4j
public class LoginCheckout implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("LoginCheckout.preHandle方法执行");
        HttpSession session = request.getSession();
        UserLoginParam userLoginParam = (UserLoginParam) session.getAttribute("user");
        if (userLoginParam==null){
            response.sendRedirect("/login.html");
        }
        return true;
    }
}
